package com.qfedu.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextHolder implements ApplicationContextAware {

    /**
     * 容器核心实现
     */
    private static ApplicationContext applicationContext;
//    ApplicationContextAware 的作用就是在创建bean ApplicationContextHolder时，会将应用上下文传递过来
    //Aware就是注入

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //让静态变量持有
        ApplicationContextHolder.applicationContext=applicationContext;
    }

    /**
     * 获取得到上下问对象
     */
    public static ApplicationContext getApplicationContext(){
        return applicationContext;
    }

}
